;;; init-basic.el --- basic config & package
;;; Commentary:
;;; Code:

;;; https://andrewjamesjohnson.com/suppressing-ad-handle-definition-warnings-in-emacs/
;; ;; ad-handle-definition: ‘align-regexp’ got redefined
;; ;; ad-handle-definition: ‘find-tag-regexp’ got redefined
(setq ad-redefinition-action 'accept)

;; 默认配置
(setq-default
 blink-cursor-interval 0.4 ;; 光标闪烁
 bookmark-default-file (locate-user-emacs-file ".bookmark.el") ;; 书签文件
 column-number-mode t ;; 列数显示
 fill-column 80 ;; 满列80
 word-wrap t ;; 折叠
 truncate-lines nil ;; 自动折行
 truncate-partial-width-windows nil
 scroll-step 1 ;; 滚动步数1
 auto-image-file-mode t  ;; 图片文件显示
 indent-tabs-mode nil ;; tab缩进
 tab-width 4 ;; tab缩进4空格
 tab-always-indent nil ;; tab缩进
 tooltip-delay 1.5 ;; tooltip 延迟时间
 create-lockfiles nil ;; 不创建 lockfile
 auto-save-default nil ;; 去掉自动保存
 mouse-yank-at-point t ;; 鼠标复制粘贴
 make-backup-files nil ;; 去掉备份文件
 save-interprogram-paste-before-kill t ;;  clipboard和kill ring交互
 scroll-preserve-screen-position 'always
 set-mark-command-repeat-pop t
 )

;; warn
(setq visible-bell nil
      ring-bell-function 'ignore)

;; auto revert
(use-package autorevert
  :defer t
  :hook (after-init . global-auto-revert-mode)
  :config
  (setq global-auto-revert-non-file-buffers t
        auto-revert-verbose nil))

;; saveplace
(use-package saveplace
  :defer t
  :hook (after-init . save-place-mode))

;; hl-line
(use-package hl-line
  :defer t
  :hook (after-init . global-hl-line-mode))

;; so-long
(use-package so-long
  :defer t
  :when (fboundp 'so-long-mode)
  :config (global-so-long-mode 1))

;; vlf 大文件
(use-package vlf
  :defer t
  :config
  (defun ffap-vlf ()
    "Find file at point with VLF."
    (interactive)
    (let ((file (ffap-file-at-point)))
      (unless (file-exists-p file)
        (error "File does not exist: %s" file))
      (vlf file))))

;; subword
(use-package subword
  :defer t
  :hook (after-init . global-subword-mode))

;; calendar
(use-package calendar
  :defer t
  :ensure nil
  :custom (calendar-mark-holidays-flag t)
  :config (setq calendar-chinese-all-holidays-flag t))

;; webjump
(use-package webjump
  :defer t
  :ensure nil
  :custom
  (webjump-sites '(
                   ;; Emacs.
                   ("Emacs Home Page" .
                    "www.gnu.org/software/emacs/emacs.html")
                   ("Savannah Emacs page" .
                    "savannah.gnu.org/projects/emacs")

                   ;; Internet search engines.
                   ("Baidu" .
                    [simple-query "baidu.com"
                                  "www.baidu.com/s?wd=" ""])
                   ("DuckDuckGo" .
                    [simple-query "duckduckgo.com"
                                  "duckduckgo.com/?q=" ""])
                   ("Google" .
                    [simple-query "www.google.com"
                                  "www.google.com/search?q=" ""])
                   ("Google Groups" .
                    [simple-query "groups.google.com"
                                  "groups.google.com/groups?q=" ""])
                   ("Wikipedia" .
                    [simple-query "wikipedia.org" "wikipedia.org/wiki/" ""]))))

;; winner-mode 窗口恢复和重启
(use-package winner-mode
  :defer t
  :ensure nil
  :defer t
  :hook (after-init . winner-mode))

;; zoom 自动调整平衡
(use-package zoom
  :defer t)

;; zoom-window 单独显示某个窗口
(use-package zoom-window
  :defer t
  :config
  (zoom-window-setup)
  (custom-set-variables
   '(zoom-window-mode-line-color "Dark")))

;; helpful 帮助
(use-package helpful
  :defer t
  :commands (helpful-at-point
             helpful-callable
             helpful-command
             helpful-function
             helpful-key
             helpful-macro
             helpful-variable)
  :bind
  ([remap display-local-help] . helpful-at-point)
  ([remap describe-function] . helpful-callable)
  ([remap describe-variable] . helpful-variable)
  ([remap describe-symbol] . helpful-symbol)
  ([remap describe-key] . helpful-key)
  ([remap describe-command] . helpful-command))

;; youdao-dict 有道词典
(use-package youdao-dictionary
  :defer t)

;; pomidor 番茄计时
(use-package pomidor
  :defer t
  :hook (pomidor-mode . (lambda ()
                          (display-line-numbers-mode -1) ; Emacs 26.1+
                          (setq left-fringe-width 0 right-fringe-width 0)
                          (setq left-margin-width 2 right-margin-width 0)
                          ;; force fringe update
                          (set-window-buffer nil (current-buffer))))
  :config (setq pomidor-sound-tick nil
                pomidor-sound-tack nil
                alert-default-style 'mode-line)
  )

(provide 'init-basic)
;;; init-basic.el ends here
